/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.orderoid.ejb.domain;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import org.joda.time.DateTime;

/**
 *
 * @author Dahlia
 */
@Entity
@Table(name = "menu")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Menu.findAll", query = "SELECT m FROM Menu m"),
    @NamedQuery(name = "Menu.findByIdMenu", query = "SELECT m FROM Menu m WHERE m.idMenu = :idMenu"),
    @NamedQuery(name = "Menu.findByNom", query = "SELECT m FROM Menu m WHERE m.nom = :nom"),
    @NamedQuery(name = "Menu.findByMontant", query = "SELECT m FROM Menu m WHERE m.montant = :montant"),
    @NamedQuery(name = "Menu.findByDateDebut", query = "SELECT m FROM Menu m WHERE m.dateDebut = :dateDebut"),
    @NamedQuery(name = "Menu.findByDateFin", query = "SELECT m FROM Menu m WHERE m.dateFin = :dateFin"),
    @NamedQuery(name = "Menu.findByPromotion", query = "SELECT m FROM Menu m WHERE m.promotion = :promotion")})
public class Menu implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "id_menu")
    private Integer idMenu;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 30)
    @Column(name = "nom")
    private String nom;
    @Basic(optional = false)
    @NotNull
    @Column(name = "montant")
    private double montant;
    @Basic(optional = false)
    @NotNull
    @Column(name = "date_debut")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateDebut;
    @Column(name = "date_fin")
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateFin;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Column(name = "promotion")
    private Double promotion;
    @JoinTable(name = "tr_menu_produit", joinColumns = {
        @JoinColumn(name = "id_menu", referencedColumnName = "id_menu")}, inverseJoinColumns = {
        @JoinColumn(name = "id_produit", referencedColumnName = "id_produit")})
    @ManyToMany
    private Collection<Produit> produitCollection;
    @JoinTable(name = "tr_restaurant_menu", joinColumns = {
        @JoinColumn(name = "id_menu", referencedColumnName = "id_menu")}, inverseJoinColumns = {
        @JoinColumn(name = "id_restaurant", referencedColumnName = "id_restaurant")})
    @ManyToMany
    private Collection<Restaurant> restaurantCollection;

    public Collection<Restaurant> getRestaurantCollection() {
        return restaurantCollection;
    }

    public void setRestaurantCollection(Collection<Restaurant> restaurantCollection) {
        this.restaurantCollection = restaurantCollection;
    }

    public Menu() {
    }

    public Menu(Integer idMenu) {
        this.idMenu = idMenu;
    }

    public Menu(Integer idMenu, String nom, double montant, Date dateDebut) {
        this.idMenu = idMenu;
        this.nom = nom;
        this.montant = montant;
        this.dateDebut = dateDebut;
    }

    public Integer getIdMenu() {
        return idMenu;
    }

    public void setIdMenu(Integer idMenu) {
        this.idMenu = idMenu;
    }

    public String getNom() {
        return nom;
    }

    public void setNom(String nom) {
        this.nom = nom;
    }

    public double getMontant() {
        return montant;
    }

    public void setMontant(double montant) {
        this.montant = montant;
    }

    public Date getDateDebut() {
        if ( dateDebut == null )
        {
            dateDebut = Calendar.getInstance().getTime();
        }
        return dateDebut;
    }

    public void setDateDebut(Date dateDebut) {
        this.dateDebut = dateDebut;
    }

    public Date getDateFin() {
        return dateFin;
    }

    public void setDateFin(Date dateFin) {
        this.dateFin = dateFin;
    }

    public Double getPromotion() {
        return promotion;
    }

    public void setPromotion(Double promotion) {
        this.promotion = promotion;
    }

    @XmlTransient
    public Collection<Produit> getProduitCollection() {
        return produitCollection;
    }

    public void setProduitCollection(Collection<Produit> produitCollection) {
        this.produitCollection = produitCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idMenu != null ? idMenu.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Menu)) {
            return false;
        }
        Menu other = (Menu) object;
        if ((this.idMenu == null && other.idMenu != null) || (this.idMenu != null && !this.idMenu.equals(other.idMenu))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "org.orderoid.ejb.domain.Menu[ idMenu=" + idMenu + " ]";
    }
    
}
